Skip to content

Fix module mode linking on macOS#697

Open
ChrisJefferson wants to merge 1 commit intomlua-rs:mainfrom
ChrisJefferson:fix-macos-module-linking
Open

Fix module mode linking on macOS#697
ChrisJefferson wants to merge 1 commit intomlua-rs:mainfrom
ChrisJefferson:fix-macos-module-linking

Conversation

@ChrisJefferson
Copy link
Copy Markdown

When building a Lua C module (cdylib with the module feature) on macOS, the linker fails with undefined symbols for the Lua API. This is because macOS requires explicit -undefined dynamic_lookup to allow unresolved symbols in shared libraries — unlike Linux which permits them by default.

The build script already had platform-specific handling for Windows (raw-dylib linking). This adds the equivalent for macOS, passing the required linker flags so that Lua symbols are resolved at load time from the host interpreter.

Fixes the issue reported in #625 -- I didn't find that PR until after I fixed it because it's closed, do you mind putting it in the source?

When building a Lua C module (cdylib with the `module` feature) on
macOS, the linker fails with undefined symbols for the Lua API. This
is because macOS requires explicit `-undefined dynamic_lookup` to
allow unresolved symbols in shared libraries — unlike Linux which
permits them by default.

The build script already had platform-specific handling for Windows
(raw-dylib linking). This adds the equivalent for macOS, passing the
required linker flags so that Lua symbols are resolved at load time
from the host interpreter.

Fixes the issue reported in mlua-rs#625.
@khvzak
Copy link
Copy Markdown
Member

khvzak commented Apr 30, 2026

I don't think this is going to work well. The build script should be in each module, not inside mlua-sys.
In particularly, if try to build a module with this change:

$ (cd tests/module && cargo build --release --features lua55)
warning: mlua-sys@0.11.0-rc.1: cargo:rustc-cdylib-link-arg was specified in the build script of mlua-sys v0.11.0-rc.1 (/Users/alex/Projects/mlua-rs/mlua/mlua-sys), but that package does not contain a cdylib target

Allowing this was an unintended change in the 1.50 release, and may become an error in the future. For more information, see <https://github.com/rust-lang/cargo/issues/9562>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants